package pacman.ml.features;

import pacman.game.Game;
import pacman.game.Constants.*;

// a compound feature that returns the minimum of the 4 DistanceToGhostFeature instances for each ghost.
public class DistanceToClosestGhostFeature extends FeatureExtractor {
	private FeatureExtractor[] distanceFeatures;
	public DistanceToClosestGhostFeature(float arg) {
		GHOST[] ghosts = GHOST.values();
		distanceFeatures = new FeatureExtractor[ghosts.length];
		int index = 0;
		for(GHOST ghost : ghosts) {
			distanceFeatures[index++] = FeatureExtractor.getInstance(DistanceToGhostFeature.class, ghost.ordinal());
		}
	}
	public float Extract(Game game) {
		float min = Float.MAX_VALUE;
		for(FeatureExtractor f : distanceFeatures) {
			min = Math.min(f.GetValue(game), min);
		}
		return min;
	}
}